
//preloading.....
load("library/common.js");

JEuler.system.loadJS("library/math.js");

(function() {

    //JEuler.system.loadJS("data/???.dat");
    JEuler.system.printCaption("063");
    JEuler.system.startTimerCount();
    
    // Find x^(n) 10^(n-1)~(10^n-1)
    // x=10 => 10^n > 10^(n-1)
    // x=9 => 9^n < 10^(n-1), this n is the upper limit
    
    //Find the upper limit of n;
    var n=1, a=9, b=1, nUpperLimit=0;
    do {
        n++;    
        a=a*9;
        b=b*10;
        if(a<b) {
            nUpperLimit = n-1;
            break;
        }
    } while(1);
    
    function countDigit(num) {
        return num.toString().length
    }
    
    var sum=0, power, count; 
    for(var i=nUpperLimit; i>=1; i--) {
        for(var j=10; j>=1; j--) {
            power = Math.pow(j, i);
            count = countDigit(power);
            if(count == i) {
                JEuler.system.print("Find " + j + "^" + i + "\t" + power);
                sum++;
            }
            //if(count < i) break;
        }
    }
    
    JEuler.system.print("Sum=" + sum);

    JEuler.system.printTimerCount();
    
})();
